package au.edu.unsw.infs3634.gamifiedlearning;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;
import android.webkit.WebView;

import java.util.ArrayList;
import java.util.List;

import au.edu.unsw.infs3634.gamifiedlearning.actiivty.TrainVideoListActivity;
import au.edu.unsw.infs3634.gamifiedlearning.actiivty.VideoListActivity;
import au.edu.unsw.infs3634.gamifiedlearning.actiivty.WebViewActivity;
import au.edu.unsw.infs3634.gamifiedlearning.adapter.ContinentsListAdapter;
import au.edu.unsw.infs3634.gamifiedlearning.model.ContinentModel;

public class Continents_list extends AppCompatActivity {
    private RecyclerView rvList;
    private ContinentsListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_continents_list);
        initView();
    }

    private void initView() {
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        setTitle("消防培训");
        rvList = findViewById(R.id.rv_list);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(RecyclerView.VERTICAL);
        rvList.setLayoutManager(linearLayoutManager);
        adapter = new ContinentsListAdapter(this, generateList(), new ContinentsListAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(ContinentModel model) {
                String name = model.getName();
                if (name.equals("学校消防安全培训")) {
                    Intent intent = new Intent(Continents_list.this, WebViewActivity.class);
                    startActivity(intent);
                } else if (name.equals("培训资料")) {
                    Intent intent = new Intent(Continents_list.this, VideoListActivity.class);
                    startActivity(intent);
                } else if (name.equals("培训视频")) {
                    Intent intent = new Intent(Continents_list.this, TrainVideoListActivity.class);
                    ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(Continents_list.this);
                    ActivityCompat.startActivity(Continents_list.this,intent,activityOptions.toBundle());
                }
               // launchDetail(name);
            }
        });
        rvList.setAdapter(adapter);
    }

    private void launchDetail(String message) {
        Intent intent = new Intent(Continents_list.this, Country_list.class);
        intent.putExtra(Country_list.MESSAGE, message);
        startActivity(intent);
    }

    private static final String[] NAMES = new String[]{
            "学校消防安全培训", "培训视频", "培训资料", "消防知识安全常识培训篇1", "消防知识安全常识培训篇2"
    };

    private static final int[] ICONS = new int[]{
        R.mipmap.ic_africa,R.mipmap.ic_asia,R.mipmap.ic_europe,R.mipmap.ic_america,R.mipmap.ic_oceania
    };

    private List<ContinentModel> generateList() {
        List<ContinentModel> list = new ArrayList<>();
        for (int i = 0; i < NAMES.length; i++) {
            ContinentModel model = new ContinentModel(NAMES[i],ICONS[i]);
            list.add(model);
        }
        return list;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                this.finish();
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}